package com.tjsinfo.tjsoa.Dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class HibernateDao extends HibernateDaoSupport implements IHibernateDao {
	public void saveObject(Object object) {
		try {
			 getHibernateTemplate().save(object);
		} catch (RuntimeException re) {
			throw re;
		}
	}
	public Integer save(Object object) {
		Integer i = 0;
		try {
			i = (Integer) getHibernateTemplate().save(object);
		} catch (RuntimeException re) {
			throw re;
		}
		return i;
	}
	public void update(Object object) {
		try {
			getHibernateTemplate().update(object);
		} catch (RuntimeException re) {
			throw re;
		}
	}
	public void delete(Object object) {
		try {
			getHibernateTemplate().delete(object);
		} catch (RuntimeException re) {
			throw re;
		}
	}
	public Object findById(Class class1,Integer id) {
		DetachedCriteria criteria = DetachedCriteria.forClass(class1);
		 criteria.add(Restrictions.eq("id", id));
		 List list = this.getHibernateTemplate().findByCriteria(criteria);
		 Object object = null;
		 if (list.size()>0) {
			 object = list.iterator().next();
		 }
		 return object;
	}
	public List findByProperty(Class class1,String PropertyName,Object value) {
		DetachedCriteria criteria = DetachedCriteria.forClass(class1);
		 criteria.add(Restrictions.eq("PropertyName", value));
		 List list = this.getHibernateTemplate().findByCriteria(criteria);
		 return list;
	}
	public String saveReturnString(Object object) {
		// TODO Auto-generated method stub
		String i = "0";
		try {
			i = (String) getHibernateTemplate().save(object);
		} catch (RuntimeException re) {
			throw re;
		}
		return i;
	}
}
